package viroyal.com.base.activity.engineering;

import android.os.Parcel;
import android.text.TextUtils;

import com.suntiago.baseui.activity.base.theMvp.model.IModel;
import com.suntiago.network.network.Api;
import com.suntiago.network.network.BaseRspObserver;
import com.suntiago.network.network.rsp.BaseResponse;

import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.schedulers.Schedulers;
import viroyal.com.base.BuildConfig;
import viroyal.com.base.activity.main.MainModel;
import viroyal.com.base.net.ApiObserver;
import viroyal.com.base.net.PhpApi;
import viroyal.com.base.net.req.DistributeSchoolRequest;
import viroyal.com.base.net.req.GetSchoolIdRequest;
import viroyal.com.base.net.rsp.DistributeSchoolResponseS;
import viroyal.com.base.net.rsp.GetDeviceInfoResponseS;
import viroyal.com.base.net.rsp.GetSchoolListResponseS;
import viroyal.com.base.net.rsp.SwipeResponseS;
import viroyal.com.dev.splash.ConfigDevice;

/**
 * @author gaochao
 */
public class EngineeringModel implements IModel {
  @Override
  public int describeContents() {
    return 0;
  }

  @Override
  public void writeToParcel(Parcel parcel, int i) {

  }


  private EngineeringModel(Parcel in) {
  }

  public EngineeringModel() {
  }

  public static final Creator<EngineeringModel> CREATOR = new Creator<EngineeringModel>() {
    @Override
    public EngineeringModel createFromParcel(Parcel in) {
      return new EngineeringModel(in);
    }

    @Override
    public EngineeringModel[] newArray(int size) {
      return new EngineeringModel[size];
    }
  };

  /**
   * 获取学校列表
   * @param action1
   * @return
   */
  public Subscription getSchoolList(Action1<GetSchoolListResponseS> action1) {
    PhpApi.get().setPhpApiConfig(BuildConfig.PHP_API_HOST, "", 0);
    return PhpApi.get().getPhpApi(ApiObserver.class)
        .getSchoolList()
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new BaseRspObserver<>(GetSchoolListResponseS.class, action1));
  }

  /**
   * 设备分配给学校
   * @param action1
   * @return
   */
  public Subscription distributeSchool(String uuid, String schoolId, Action1<DistributeSchoolResponseS> action1) {

    DistributeSchoolRequest request = new DistributeSchoolRequest(uuid, schoolId);
    return PhpApi.get().getPhpApi(ApiObserver.class)
        .distributeSchool(request)
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new BaseRspObserver<>(DistributeSchoolResponseS.class, action1));
  }


  public Subscription getDeviceInfo(String deviceId, Action1<GetDeviceInfoResponseS> action1) {
    PhpApi.get().setPhpApiConfig(BuildConfig.PHP_API_HOST, "", 0);
    GetSchoolIdRequest request = new GetSchoolIdRequest(deviceId);

    return PhpApi.get().getPhpApi(ApiObserver.class)
        .getDeviceInfo(request)
        .subscribeOn(Schedulers.newThread())
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe(new BaseRspObserver<>(GetDeviceInfoResponseS.class, action1));
  }
}
